package com.example.qxfw.ybzz.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.qx.ForecastInfo;
import com.example.qxfw.common.entity.qx.Weather;
import com.example.qxfw.common.entity.zy.BaseProduct;
import com.example.qxfw.common.entity.zy.WeatherFcst;
import com.example.qxfw.rcyw.pojo.JobMake;
import com.example.qxfw.rcyw.service.JobMakeService;
import com.example.qxfw.ybzz.service.BaseProductService;
import com.example.qxfw.ybzz.service.ForecastInfoService;
import com.example.qxfw.ybzz.service.SysConfigService;
import com.example.qxfw.ybzz.service.WeatherFcstService;
import com.example.qxfw.ybzz.service.WeatherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@ApiIgnore
@Api(tags = "预报制作-城镇报制定")
@RestController
@CrossOrigin
@RequestMapping("/czbzd")
public class CzbzdController {

    @Autowired
    private WeatherService weatherService;

    @Autowired
    private ForecastInfoService forecastInfoService;

    @Autowired
    private SysConfigService sysConfigService;

    @Autowired
    private WeatherFcstService weatherFcstService;

    @Autowired
    private BaseProductService baseProductService;

    @Autowired
    private JobMakeService jobMakeService;

    @ApiOperation("获取天气信息")
    @GetMapping("/getWeather")
    public SysResult getWeather(){
        List<Weather> weathers = weatherService.getWeather();
        return SysResult.success(weathers,weathers.size());
    }

    @ApiOperation("获取天气信息")
    @GetMapping("/getWind")
    public SysResult getWind(){
        List<Weather> weathers = weatherService.getWind();
        return SysResult.success(weathers,weathers.size());
    }

    @ApiOperation("获取天气信息")
    @GetMapping("/getWindd")
    public SysResult getWindd(){
        List<Weather> weathers = weatherService.getWindd();
        return SysResult.success(weathers,weathers.size());
    }

    @ApiOperation("获取预报信息")
    @GetMapping("/getForecast")
    public SysResult getForecase(String dateChar,String timeChar,String city){
        List<ForecastInfo> forecastInfos = forecastInfoService.searchForecastInfo(dateChar,timeChar,city);
        return SysResult.success(forecastInfos,forecastInfos.size());
    }

    @ApiOperation("NEW获取预报信息")
    @GetMapping("/newGetForecast")
    public SysResult newGetForecast(String dateChar,String timeChar,String city){
        List<ForecastInfo> forecastInfos = forecastInfoService.newGetForecast(dateChar,timeChar,city);
        if (forecastInfos != null) {
            return SysResult.success(forecastInfos, forecastInfos.size());
        }else {
            return SysResult.fail("数据库无相关数据信息！");
        }
    }



    @ApiOperation("获取预报信息")
    @GetMapping("/getForecast1")
    public SysResult getForecase1(String dateChar,String timeChar,String city){
        List<ForecastInfo> forecastInfos = forecastInfoService.getList2(dateChar,timeChar,city);
        return SysResult.success(forecastInfos,forecastInfos.size());
    }

    @ApiOperation("获取站点信息")
    @GetMapping("/getStationInfo")
    public SysResult getStationInfo(String city){
        List<ForecastInfo> forecastInfos = forecastInfoService.getStationInfo(city);
        return SysResult.success(forecastInfos);
    }

    @ApiOperation("获取最大时间")
    @GetMapping("/getMaxTime")
    public SysResult getMaxTime(String timeChar,String city){
        String maxTime = forecastInfoService.getMaxTime1(timeChar, city);
        return SysResult.success(maxTime);
    }

    @ApiOperation("获取模板数据")
    @GetMapping("/getTemplates")
    public SysResult getTemplates(String paramName){
        List<String> list = sysConfigService.getTemplates(paramName);
        return SysResult.success(list,list.size());
    }

    @ApiOperation("保存预报")
    @PostMapping("/saveWeatherFcst")
    public SysResult saveWeatherFcst(@RequestBody WeatherFcst weatherFcst){
        int rows = weatherFcstService.saveWeather(weatherFcst);
        return SysResult.success(rows);
    }

    @ApiOperation("获取BaseProduct数量")
    @GetMapping("/countBaseProduct")
    public SysResult countBaseProduct(String productName, String productType){
        List<String> productNames = baseProductService.getProductName(productName, productType);
        return SysResult.success(productNames,productNames.size());
    }

    @ApiOperation("更新BaseProduct")
    @PostMapping("/updateBaseProduct")
    public SysResult updateBaseProduct(@RequestBody BaseProduct baseProduct){
        int rows = baseProductService.updateProduct(baseProduct);
        return SysResult.success(rows);
    }

    @ApiOperation("插入BaseProduct")
    @PostMapping("/saveBaseProduct")
    public SysResult saveBaseProduct(@RequestBody BaseProduct baseProduct){
        System.out.println(baseProduct.toString());
        int rows = baseProductService.save(baseProduct);
        return SysResult.success(rows);
    }

    @ApiOperation("更新日常业务信息")
    @PostMapping("/updateJobMake")
    public SysResult updateJobMake(JobMake jobMake){
        int rows = jobMakeService.update1(jobMake);
        return SysResult.success(rows);
    }
}
